<?php
declare(strict_types=1);

namespace app\admin\validate;

use think\Validate;

class AdminValidate extends Validate
{
    protected $rule = [
        'admin_id' => 'require|number',
        'username' => 'require|length:4,32',
        'password' => 'require|length:6,32',
        'nickname' => 'max:32',
        'avatar' => 'url',
        'status' => 'in:0,1',
        'role_ids' => 'array'
    ];

    protected $message = [
        'admin_id.require' => '管理员ID不能为空',
        'admin_id.number' => '管理员ID必须为数字',
        'username.require' => '用户名不能为空',
        'username.length' => '用户名长度必须在4-32个字符之间',
        'password.require' => '密码不能为空',
        'password.length' => '密码长度必须在6-32个字符之间',
        'nickname.max' => '昵称最多32个字符',
        'avatar.url' => '头像必须是有效的URL地址',
        'status.in' => '状态值只能是0或1',
        'role_ids.array' => '角色格式错误'
    ];

    protected $scene = [
        'add' => ['username', 'password', 'nickname', 'avatar', 'status', 'role_ids'],
        'edit' => ['admin_id', 'username', 'nickname', 'avatar', 'status', 'role_ids']
    ];
} 